package com.yang.webhook.modules.controller;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.yang.webhook.common.utils.AjaxUtil;
import com.yang.webhook.common.utils.R;
import com.yang.webhook.modules.entity.UserInfo;
import com.yang.webhook.modules.entity.WisLog;

/**
 * 测试类
 * 
 * @author YC
 *
 */
@RestController
@RequestMapping(value = "/HelloWorld")
public class HelloWorldHandlers extends BaseControl {

	/**
	 * 1. 使用RequestMapping注解来映射请求的URL 2. 返回值会通过视图解析器解析为实际的物理视图,
	 * 对于InternalResourceViewResolver视图解析器，会做如下解析 通过prefix+returnVal+suffix
	 * 这样的方式得到实际的物理视图，然后会转发操作 "/WEB-INF/views/success.jsp"
	 * 
	 * @return
	 * @throws Exception
	 */
	// @WebLoginRequired
	@RequestMapping(value = "/helloworld.do")
	public R hello(WisLog wislog, HttpServletRequest request, HttpServletResponse response) {
		System.out.println(wislog);
		wislog.setLogRecordingtime(new Date());
		wislog.setLogSysurl("www.baidu.com");
		wislog.setLogId("logId");
		return R.ok().put("data", wislog);
	}

	/**
	 * 访问方式 <a href="/testPathVariable.do/1">testPathVariable</a>
	 */
	@RequestMapping("/testPathVariable.do")
	public String testPathVariable(@RequestParam(value = "id") Integer id) {
		System.out.println("testPathVariable:" + id);
		return "success";
	}

	/**
	 * 访问方式
	 * <a href="/testRequestParam.do?username=杨成&age=12"> testRequestParam</a>
	 */
	@RequestMapping(value = "/testRequestParam.do")
	public void testRequestParam(@RequestParam(value = "username") String username,
			@RequestParam(value = "age", required = false, defaultValue = "0") int age, HttpServletRequest request,
			HttpServletResponse response) {
		System.out.println("testRequestParam" + " username:" + username + " age:" + age);
		AjaxUtil.ajaxResponse(response, username);
	}

	/**
	 * 查询个人信息
	 * 
	 * @param id
	 * @return
	 */
	@RequestMapping(value = "/porfile.do")
	public void porfile(@RequestParam(value = "id") int id, @RequestParam(value = "name") String name,
			@RequestParam(value = "status") boolean status, HttpServletRequest request, HttpServletResponse response) {

		System.out.println("person:" + " id:" + id + " username:" + name + " age:" + status);
		// return new Person(id, name, status);
		AjaxUtil.ajaxResponse(response, "状态=" + status);
	}

	/**
	 * 登录
	 * 
	 * @param person
	 * @return
	 */
	@RequestMapping(value = "/person.do")
	public void login(HttpServletRequest request, HttpServletResponse response) {

		System.out.println("进入" + request.getParameter("name"));
		// System.out.println("名字=" + person.getName());
		AjaxUtil.ajaxResponse(response, "状态=");
		// return person;
	}

	@RequestMapping("/saysth.do")
	public void test(UserInfo user, HttpServletRequest request, HttpServletResponse response) {
		System.out.println(user.getId());
		System.out.println(user.getName());

		AjaxUtil.ajaxResponse(response, "状态=" + user.getName());
	}

}